//
//  StarsView.swift
//  WangPu
//
//  Created by xiaozhi on 15/10/16.
//  Copyright © 2015年 zhixiao. All rights reserved.
//

import UIKit

class StarsView: UIView {
    var starsTotalNumber:NSInteger = 5
    var currentStars:NSInteger = 0
    var imageArray:[UIImageView]! = []
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    func createSubViews()->Void{
        let width = bounds.size.width/5.0
        let height = bounds.size.height
        for i in 0..<self.starsTotalNumber{
            let imagev = UIImageView(frame: CGRectMake(width*CGFloat(i), 0, width, height))
            imagev.image = UIImage(named: "down-collection_star-")
            imagev.contentMode = UIViewContentMode.ScaleAspectFit
            self.addSubview(imagev)
            imageArray?.append(imagev)
        }
    }
    func setSelectNumber(index:NSInteger)->Void{
        for i in 0..<self.starsTotalNumber{
            if i < index{
                self.imageArray[i].image = UIImage(named: "down-collection_star-")
            }
            else{
                 self.imageArray[i].image = UIImage(named: "")
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        //        self.backgroundColor = UIColor(patternImage: UIImage(named: "tab-bg")!)
        backgroundColor = UIColor.whiteColor()
        self.createSubViews()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.createSubViews()
    }
}
